//
//  AppDelegate+configure.m
//  KEREN
//
//  Created by MW on 2023/3/13.
//

#import "AppDelegate+configure.h"
@implementation AppDelegate (configure)
- (void)configure{
    [WXApi registerApp:WXAppID universalLink:WXAppLink];
    [AMapServices sharedServices].apiKey = GDKey;
    [MAMapView updatePrivacyShow:AMapPrivacyShowStatusDidShow privacyInfo:AMapPrivacyInfoStatusDidContain];
    [MAMapView updatePrivacyAgree:AMapPrivacyAgreeStatusDidAgree];
}


- (void)configLog{
    [DDLog addLogger:[DDOSLogger sharedInstance]];
    
    DDLogFileManagerDefault *fileLoggerManager = [[DDLogFileManagerDefault alloc] initWithLogsDirectory:[self logPath]];
    DDFileLogger *fileLogger = [[DDFileLogger alloc] initWithLogFileManager:fileLoggerManager]; // File Logger
    //重用log文件，不要每次启动都创建新的log文件(默认值是NO)
    fileLogger.doNotReuseLogFiles = NO;
    //log文件在24小时内有效，超过时间创建新log文件(默认值是24小时)
    fileLogger.rollingFrequency = 60*60*24;
    //log文件的最大20M(默认值1M)
    fileLogger.maximumFileSize = 1024*1024*20;
    //最多保存7个log文件(默认值是5)
    fileLogger.logFileManager.maximumNumberOfLogFiles = 7;
    //log文件夹最多保存10M(默认值是140M)
    fileLogger.logFileManager.logFilesDiskQuota = 1014*1024*140;
    //添加文件写入logger
    [DDLog addLogger:fileLogger];
}

-(DDLogFileManagerDefault *)logFileManager{
    NSArray *array = [DDLog allLoggers];
    for(id<DDLogger> logger in array){
        if([logger isKindOfClass:[DDFileLogger class]]){
            DDLogFileManagerDefault *logFileManager = ((DDFileLogger *)logger).logFileManager;
            return logFileManager;
        }
    }
    return nil;
}


-(NSString *)logPath{
    
    NSURL *logDirectory = [[NSURL fileURLWithPath:[self searchPath]] URLByAppendingPathComponent:@"Logs" isDirectory:YES];
    return logDirectory.path;
}

-(NSString *)searchPath{
    NSString *path =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    return path;
}

@end
